<#include "common/common.html"/>
<meta charset="UTF-8">
<script type="text/javascript">
function formatStatus(value,row,index){
	if(value==0){
		return "未处理";
	}else if(value==1){
		return "已处理";
	}else{
		return "已删除";
	}
}

function query(formId) {
	var serializeObj = {};
	var array = $('#' + formId).serializeArray();
	$(array).each(
			function() {
				if (serializeObj[this.name]) {
					if ($.isArray(serializeObj[this.name])) {
						serializeObj[this.name].push(this.value);
					} else {
						serializeObj[this.name] = [serializeObj[this.name], this.value ];
					}
				} else {
					serializeObj[this.name] = this.value;
				}
			});
	queryData(serializeObj);
}

function multiHandle(actUrl){
	var rows = $('#datagrid').datagrid('getSelections');
	if (rows.length>0){
    	var ids = [];
    	for(var i=0; i<rows.length; i++){
    		ids.push(rows[i].id);
    	}
    	url = $("#base").val()+"/"+actUrl;
         $.messager.confirm('处理意向','确定要处理当前意向资料吗？',function(r){
            if (r){
                $.post(url,{ids:ids.join(',')},function(result){
                	var result = eval('('+result+')');
                	if (result.errorMsg){
                 	   $.messager.alert('错误',result.errorMsg,'error');
                    } else if(result.infoMsg){
                 	   $.messager.alert('提示',result.infoMsg,'info');
                    }else{
                       $('#datagrid').datagrid('reload');   
                    }
                });
            }
        });
    }else{
    	$.messager.alert('提示','请选择至少一条数据进行操作','info');
    }
   }
 
function editIntention(title,actUrl,dlgId,fmId){
	var rows = $('#datagrid').datagrid('getSelections');
	$("#"+fmId).form('clear');
    if (rows&&rows.length==1){
    	var type=rows[0].type;
    	if(type == 101){
    		$("#zjMode").show();
    		$("#xmMode").hide();
    	}else if(type ==102){
    		$("#zjMode").hide();
    		$("#xmMode").show();
    	}else{
    		$("#zjMode").show();
    		$("#xmMode").show();
    	}
    	
    	
    	$('#industry').combobox({   
    	    url: '${base}/industry/queryAll',
    	    valueField:'id',
    	    textField:'industryName',
    	    required: true,
    	    multiple:type==101?false:true,
    	    width:200,
    	    onSelect:function(record){
    	    	var nodes = $('#industry').combobox('getValues');
    	    	if(record.id == 97 ){
    	    		$.each(nodes, function(i,n){
    	    			if(n != 97){
   	    				 $('#industry').combobox('unselect', n);
    	    			}
	   	    		});
    	    	}else{
    	    		$('#industry').combobox('unselect', 97);
    	    	}
    	    }
    	});
    	$('#district').combobox({   
    	    url: '${base}/cityinfo/findAllProvince',    
    	    required: true,
    	    valueField:'postcode',
    	    textField:'cityName',
    	    multiple:type==101?false:true,
    	    width:200,
    	    loadFilter:function(data){
			    data.unshift({postcode:'0',cityName:'全国'});
			    return data;
		    },
    	    onSelect:function(record){
    	    	var nodes = $('#district').combobox('getValues');
    	    	if(record.postcode == 0 ){
    	    		$.each(nodes, function(i,n){
    	    			if(n != 0){
   	    				 $('#district').combobox('unselect', n);
    	    			}
	   	    		});
    	    	}else{
    	    		$('#district').combobox('unselect', 0);
    	    	}
    	    }
    	});
    	$("#"+dlgId).dialog('open').dialog('setTitle',title);
    	$("#"+fmId).form('load',rows[0]);
        url = "${base}/"+actUrl+"?id="+rows[0].id;
    }else{
    	$.messager.alert('提示','请选择一条数据进行操作','info');
    }
}
function formatOpers(val,row,index){
   //在控制层判断匹配类型
	return "<a href='javascript:showMarry("+row.id+","+row.type+")'>匹配</a>";
}

var $winst;
function showMarry(id,type){
   var windowWidth =$(window.parent).width();
   var windowHeight=$(window.parent).height();
   var width= windowWidth-200;
   var height=windowHeight-200;
   var top=(windowHeight-height)/2;
   var left=(windowWidth-width)/2;
    $winst = $('#intentionDiv').window({
    	href: 'intention/showMarry?id='+id+'&noCache=random'+'&type='+type,
        title: '匹配管理',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });
    $('#datagrid').datagrid('clearSelections');
    $winst.window('open');
}
</script>
<style type="text/css">
input, select, textarea {
	font: 12px tahoma, arial, \5b8b\4f53, sans-serif;
	font-size: 100%
}

input, p {
	margin: 0;
	padding: 0;
	list-style: none
}

.add-form p {
	padding: 5px 0 5px 30px;
}

.add-form p label {
	width: 100px;
	text-align: right;
	display: inline-block;
}
</style>
<table
	     class="easyui-datagrid"   
	     id="datagrid"  
         title="意向管理"  
         url="${base}/intention/list"
         toolbar="#searchtool,#toolbar" 
         pagination="true"
         rownumbers="true" 
         data-options="fit:false,border:false,pageSize:20" >  
    <thead>  
        <tr>
            <th field="id" align="center" checkbox="true"></th>  
            <th field="intro" align="center" width="200px">标题</th>
            <th field="industryName" align="center" width="150px">行业</th>
            <th field="districtName" align="center" width="150px">地区</th>
            <th field="userName" align="center" width="100px">发布人</th>     
            <th field="phone" align="center" width="100px">发布人电话</th>     
            <th field="amount" align="center" width="80px">金额（万）</th>
            <th field="modeName" align="center" width="40px">方式</th>     
            <th field="status" align="center" width="60px" formatter="formatStatus">处理状态</th>
            <th field="projectId" align="center" width="50px">项目ID</th>
            <th field="authName" align="center" width="60px">认证方式</th>    
            <th field="typeName" align="center" width="60px">身份类型</th>     
            <th field="pushTime" align="center" width="100px">发布时间</th>
            <th field="content" align="center" width="100px">描述</th>
            <th field="handlePerson" align="center" width="100px">操作员</th>  
            <th field="handleTime" align="center" width="100px">操作时间</th>  
            <th field="note" align="center" width="100px">备注</th>
            <th field="operates" width="100px" formatter="formatOpers">操作</th> 
        </tr>  
    </thead>  
</table>  
<div id="searchtool" style="padding:5px">
    <form id="searchForm" method="post">
     <span>所属行业:</span>
	 <input class="easyui-combobox" name="industry" data-options="valueField:'id',editable:true,textField:'industryName',url:'${base}/industry/queryAll',loadFilter:function(data){data.unshift({id:'',industryName:'所有'});return data;}" /> 
	 <span>所在地区:</span>
	 <input class="easyui-combobox" name="province" data-options="valueField:'postcode',editable:true,value:'0',textField:'cityName',url:'${base}/cityinfo/findAllProvince',loadFilter:function(data){data.unshift({postcode:'0',cityName:'全国'});return data;}" />
	 <span>处理状态:</span>
	 <select class="easyui-combobox" name="status" style="width:200px;">   
	    <option value="">全部</option>   
	    <option value="0">未处理</option>   
	    <option value="1">已处理</option>   
	    <option value="2">已删除</option>   
	</select>
	<span>身份类型:</span> 
	<select class="easyui-combobox" name="type" style="width:200px;">   
    <option value="">全部</option>   
    <option value="101">项目方</option>   
    <option value="102">资金方</option>   
	</select> 
	<span>起始时间:</span>
	<input id="startDate" name="startDate" type="text" class="easyui-datebox" />
	<span>截止时间:</span>
	<input id="endDate" name="endDate" type="text" class="easyui-datebox" />
	<span>关键字:</span>
	<input type="text" id="keyWord" name="keyWord" data-options="prompt:'标题/姓名/手机号'" class="easyui-textbox" size=20 />  
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:query('searchForm');">搜索</a>
    </form>  
</div>  
<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:editIntention('意向编辑','intention/edit','intention-dlg','intention-fm');">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:multiHandle('intention/multiHandle');">已处理</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:multiDel('intention/multiDelete');">删除</a>
</div>
	<!--编辑弹框开始-->
		<div id="intention-dlg" class="easyui-dialog" title="意向编辑" style="padding: 10px 100px 10px 0;" data-options="iconCls: 'icon-save',closed: true,modal:true,buttons:'#intention-dlg-buttons'" >
			<form id="intention-fm" method="post" class="add-form">
				<div>
					<p>
						<label>意向标题：</label> <input name="intro" class="easyui-textbox" type="text" required="true" />
					</p>
					<p>
						<label>所属行业：</label> <input id="industry" name="industry" />
					</p>
						
					<p>
						<label>所在地区：</label>
						 <input id="district" name="district" />
					</p>
					<p>
						<label>发布人：</label> <input id="userName" name="userName" class="easyui-textbox" type="text" disabled="true" />
					</p>
					<div id="xmMode">
					<p>
						<label>项目类型：</label> 
						         <input name="mode" type="radio" value="301" />股权<input name="mode" type="radio" value="302" />债权<input name="mode" type="radio" value="303" />资产交易<input name="mode" type="radio" value="304" />政府招商<br/>
					                        
					</p>
					</div>
					<div id="zjMode">
					<p>
						<label>项目类型：</label> 
					            <input name="mode" type="radio" value="301" />股权<input name="mode" type="radio" value="302" />债权<input name="mode" type="radio" value="303" />资产交易<input name="mode" type="radio" value="304" />政府招商<br/>
					</p>
					</div>
					<p>
						<label>金额：</label> <input name=amount class="easyui-numberbox" />
					</p>
					<p>
						<label>身份类型：</label> <select id="type" class="easyui-combobox" name="type" style="width:200px;">  
											    <option value="102">资金方</option>   
											    <option value="101">项目方</option>   
											  </select> 
					</p>
					<p>
						<label>意向描述：</label> <input name="content" class="easyui-textbox" type="text" data-options="height:70,width:200,multiline:true,required: true,validType:'maxLength[200]'" />
					</p>
					<p>
						<label>备注：</label> <input name="note" class="easyui-textbox" type="text" data-options="height:70,width:200,multiline:true,validType:'maxLength[200]'" />
					</p>
				</div>
			</form>
		</div>
		<div id="intention-dlg-buttons">
		    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:submit('intention-dlg','intention-fm');" style="width:90px">提交</a>
		    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#intention-dlg').dialog('close');" style="width:90px">取消</a>
		</div>		
		<div id="intentionDiv" class="easyui-window"  style="padding:10px 20px" closed="true" modal="true">
</div>
	<!--编辑弹框结束-->